﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Webshop.Models;

namespace Webshop.Controllers
{
    public class HomeController : Controller
    {
        // GET: /Home/
        WebshopEntities storeDB = new WebshopEntities();
        public ActionResult Index()
        {
            var products = GetTopSellingProducts(5); 
            return View(products);
        }

        private List<Product> GetTopSellingProducts(int count)
        {
            return storeDB.Products.OrderByDescending(a => a.OrderDetails.Count()).Take(count).ToList();
        }
    }
}
